

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../../utils/ColorUtils.dart';

class ErrorDialog extends StatefulWidget{

  const ErrorDialog({super.key,});

  @override
  State<StatefulWidget> createState() {
    return _ErrorDialog();
  }

}

class _ErrorDialog extends State<ErrorDialog>{

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }
  @override
  Widget build(BuildContext context) {

    return WillPopScope(
      // 拦截返回按钮
        onWillPop: () async {
          return true;
        },
        child: ConstrainedBox(
          constraints: BoxConstraints.expand(),
          child: GestureDetector(
            onTap: () {

            },
            child: Material(
              color: ColorUtils.color_transparent,
              child: GestureDetector(
                onTap: () {
                  // 在非强更模式下，防止误触弹框内容导致关闭弹框
                },
                child: Center(
                  child: Container(
                    margin: EdgeInsets.symmetric(horizontal: 10),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Container(
                          padding: const EdgeInsets.symmetric(horizontal: 15),
                          decoration: const ShapeDecoration(
                              color: ColorUtils.color_white,
                              shape:  RoundedRectangleBorder(
                                  borderRadius: BorderRadius.only(
                                      topLeft: Radius.circular(15.0),
                                      topRight: Radius.circular(15.0),
                                      bottomLeft: Radius.circular(15.0),
                                      bottomRight: Radius.circular(15.0)))),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              const SizedBox(height: 20,),
                              const Text('提示',style: TextStyle(fontSize: 16,color: ColorUtils.color_black),),
                              const SizedBox(height: 20,),
                              const Text("升级失败，请联系客服",style: TextStyle(fontSize: 14,color: ColorUtils.color_black)),
                              const SizedBox(height: 20,),
                              Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  const SizedBox(height: 20,),
                                  Row(
                                    children: [
                                      Expanded(
                                          flex: 1,
                                          child: Container(
                                            alignment: Alignment.center,
                                            height: 40,
                                            decoration: BoxDecoration(
                                                borderRadius: const BorderRadius.all(Radius.circular(30)),
                                                border:Border.all(
                                                  color: ColorUtils.color_black,
                                                  width: 1,
                                                )
                                            ),
                                            child: GestureDetector(
                                              onTap: (){
                                                Navigator.pop(context);
                                              },
                                              child: const Text('取消',style: TextStyle(fontSize: 14,color: ColorUtils.color_black),),
                                            ),
                                          )),
                                      const SizedBox(width: 10,),
                                      Expanded(
                                          flex: 1,
                                          child: Container(
                                            alignment: Alignment.center,
                                            height: 40,
                                            decoration: const BoxDecoration(
                                              borderRadius: BorderRadius.all(Radius.circular(30)),
                                              gradient: LinearGradient(
                                                begin: Alignment.topCenter, // 渐变起始位置
                                                end: Alignment.bottomCenter, // 渐变结束位置
                                                colors: [ColorUtils.color_6dd400, ColorUtils.color_20c468], // 渐变色数组
                                              ),
                                            ),
                                            child: GestureDetector(
                                              onTap: () async{
                                                Navigator.pop(context);
                                                if(await canLaunch('tel:075526652852')){
                                                  await launch('tel:075526652852');
                                                }
                                              },
                                              child: const Text('联系客服',style: TextStyle(fontSize: 14,color: ColorUtils.color_white),),
                                            ),
                                          ))
                                    ],
                                  ),
                                ],
                              ),

                              const SizedBox(
                                height: 20,
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ),
        ));

  }
}